﻿using ManagoMes.Read.API.Applications.ProductionRead;
using ManagoMes.Read.API.Applications.QRUPCSearch;
using ManagoMes.Read.API.Applications.SellStockSearchRead;
using ManagoMes.Read.API.Applications.SupplierSearch;
using ManagoMes.Read.API.Applications.SupplierSearchRead;
using MangoMes.Commont.Domain.ProductionWorking;
using MangoMes.Commont.Domain.QRUPC;
using MangoMes.Commont.Domain.Suppliers;
using MangoMes.Commont.DTOs;
using MediatR;
using Microsoft.AspNetCore.Mvc;


namespace ManagoMes.Read.API.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class UserLiController : ControllerBase
    {
        private readonly IMediator _mediator;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="mediator"></param>
        public UserLiController(IMediator mediator)
        {
            _mediator = mediator;
        }
        /// <summary>
        /// 供应商查询显示
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<PageDTO<SupplierDTO>> SearchSupplier(SupplierSearchCommand info)
        {
            try
            {
                var cou = await _mediator.Send(info);
                return cou;
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 供应商等级绑定
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ResultsDTO<SupplierClass>> SearchSupplierClass(SupplierClassSearchCommand info)
        {
            try
            {
                var cou = await _mediator.Send(info);
                return cou;
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 销售出库列表
        /// </summary>
        /// <param name="com"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<PageDTO<SellStockDTO>> SearchSellStock(SellStockSearchCommand com)
        {
            try
            {
                var cou = await _mediator.Send(com);
                return cou;
            }
            catch (Exception)
            {
                throw;
            }
        }
        /// <summary>
        /// 销售出库单回填
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ResultsDTO<SellStockDTO>> BackfillSellStock(SellStockBackfillCommand cmd)
        {
            try
            {
                var cou = await _mediator.Send(cmd);
                return cou;
            }
            catch (Exception)
            {
                throw;
            }
        }
        /// <summary>
        /// 产品销售列表+分页
        /// </summary>
        /// <param name="com"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<CodePageDTO<ProductsSaleDTO>> SearchProductsSale(ProductsSaleSearchCommand com)
        {
            try
            {
                var cou = await _mediator.Send(com);
                return cou;
            }
            catch (Exception)
            {
                throw;
            }
        }
        /// <summary>
        /// 库存物资列表+分页
        /// </summary>
        /// <param name="com"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<CodePageDTO<MaterialSearchDTO>> SearchMaterial(MaterialSearchCommand com)
        {
            try
            {
                var cou = await _mediator.Send(com);
                return cou;
            }
            catch (Exception)
            {
                throw;
            }
        }

        /// <summary>
        /// 生产报工列表+分页+条件查询
        /// </summary>
        /// <param name="com"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<CodePageDTO<ProductionDTO>> SearchProduction(ProductionSearchCommand com)
        {
            try
            {
                var cou = await _mediator.Send(com);
                return cou;
            }
            catch (Exception)
            {
                throw;
            }
        }
        /// <summary>
        /// 绑定生产报工类型
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ResultsDTO<ProductionType>> SearchProductionType(ProductionTypeShowCommand info)
        {
            try
            {
                var cou = await _mediator.Send(info);
                return cou;
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 生产报工回填
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ResultsDTO<ProductionDTO>> BackfillProduction(ProductionBackfillCommand cmd)
        {
            try
            {
                var cou = await _mediator.Send(cmd);
                return cou;
            }
            catch (Exception)
            {
                throw;
            }
        }
        /// <summary>
        /// 赋码管理列表+分页
        /// </summary>
        /// <param name="com"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<CodePageDTO<QRUPCDTO>> SearchQUCode(QUCodeSearchCommand com)
        {
            try
            {
                var cou = await _mediator.Send(com);
                return cou;
            }
            catch (Exception)
            {
                throw;
            }
        }
        /// <summary>
        /// 入库统计
        /// </summary>
        /// <param name="com"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<PageDTO<MaterialSDTO>> SearchSMaterial(MaterialSSearchCommand com)
        {
            try
            {
                var cou = await _mediator.Send(com);
                return cou;
            }
            catch (Exception)
            {
                throw;
            }
        }
        /// <summary>
        /// 赋码管理反填
        /// </summary>
        /// <param name="com"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ResultsDTO<QUCode>> SearchShow(QUCodeBackfillCommand com)
        {
            try
            {
                var cou = await _mediator.Send(com);
                return cou;
            }
            catch (Exception)
            {
                throw;
            }
        }
    }
}
